package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.vo.OrderVO;
import com.sky.vo.SalesTop10ReportVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {

    /**
     * @description: 向订单表插入数据
     * @author: zhouzhijie
     * @date: 2023/11/22 21:03
     * @param: [orders]
     * @return:
     **/
    void insert(Orders orders);

    /**
     * 根据订单号查询订单
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);


    /**
     * @description: 动态历史订单查询
     * @author: zhouzhijie
     * @date: 2023/11/24 23:37
     * @param: [ordersPageQueryDTO]
     * @return:
     **/
    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * @description: 根据id查询订单详情
     * @author: zhouzhijie
     * @date: 2023/11/25 17:30
     * @param: [id]
     * @return:
     **/
    @Select("select * from orders where id = #{id}")
    Orders getById(Long id);

    /**
     * @description: 根据订单id查询订单和地址
     * @author: zhouzhijie
     * @date: 2023/11/25 17:44
     * @param: [id]
     * @return:
     **/
    OrderVO getByIdWithAddress(Long id);

    /**
     * @description: 根据状态，分别查询出待接单、待派送、派送中的状态数量
     * @author: zhouzhijie
     * @date: 2023/11/26 12:25
     * @param: [toBeConfirmed]
     * @return:
     **/
    @Select("select count(id) from orders where status = #{status}")
    Integer countStatus(Integer status);


    /**
     * @description: 根据订单状态和下单时间查询订单
     * @author: zhouzhijie
     * @date: 2023/11/27 11:18
     * @param: [status, orderTime]
     * @return:
     **/
    @Select("select * from orders where status = #{status} and order_time < #{orderTime}")
    List<Orders> getByStatusAndOrderTimeLt(Integer status, LocalDateTime orderTime);

    /**
     * @description: 根据条件动态查询营业额数据
     * @author: zhouzhijie
     * @date: 2023/11/28 16:59
     * @param: [map]
     * @return:
     **/
    Double sumByMap(Map map);

    /**
     * @description: 根据条件动态查询订单数量
     * @author: zhouzhijie
     * @date: 2023/11/28 21:07
     * @param: [map]
     * @return:
     **/
    Integer countByMap(Map map);

    /**
     * @description: 统计指定时间区间内的查询销量排名top10
     * @author: zhouzhijie
     * @date: 2023/11/29 10:01
     * @param: [beginTime, endTime]
     * @return:
     **/
    List<GoodsSalesDTO> getSalesTop10(LocalDateTime beginTime, LocalDateTime endTime);
}
